package com.jwell.panrank.presenter

import com.jwell.driverapp.tools.BaseSubscriber
import com.jwell.driverapp.ui.base.BasePresenter
import com.jwell.panrank.contract.ForgetPasswordContract
import com.jwell.panrank.model.ForgetPasswordModel
import org.json.JSONObject
import org.reactivestreams.Subscription

/**
 * Created by 76577 on 2018/4/4.
 * 忘记密码
 */
class ForgetPasswordPresenter : ForgetPasswordContract.Presenter, BasePresenter<ForgetPasswordContract.View>() {
    private val model by lazy {
        ForgetPasswordModel()
    }

    override fun regSendMsg(phone: String, userType: Int) {
        model.regSendMsg(phone, userType, object : BaseSubscriber() {
            override fun setSubscription(s: Subscription) {
                mSubscription = s
            }

            override fun succeed(data: JSONObject) {
                getView()?.hideProgress()
                getView()?.getCodeSucceed()
            }

            override fun onFailed(msg: String) {
                getView()?.hideProgress()
                getView()?.toast(msg)
            }
        })
    }

    override fun userRegPwd(phone: String, msgCode: String, pwd: String, userType: Int) {
        model.userRegPwd(phone, msgCode, pwd, userType, object : BaseSubscriber() {
            override fun setSubscription(s: Subscription) {
                mSubscription = s
            }

            override fun succeed(data: JSONObject) {
                getView()?.hideProgress()
                getView()?.resetSucceed(pwd)
            }

            override fun onFailed(msg: String) {
                getView()?.hideProgress()
                getView()?.toast(msg)
                getView()?.resetFail()
            }
        })
    }
}